﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Portal.Core.Adapters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Portal.Core.Tests.Units;
using Portal.Model;
using FluentAssertions;
using Rhino.Mocks;

namespace Portal.Core.Adapters.Tests.Units
{
	[TestClass()]
	public class UserAdapterTests : BaseTests
	{
		private IUser _user = null;

		protected override void InitializeTest()
		{
			base.InitializeTest();
			_user = Mocks.Stub<IUser>();
		}

		#region DisplayName

		[TestMethod()]
		[ExpectedException(typeof(ArgumentNullException))]
		public void DisplayName_UserIsNotInitialized_ThrowsException()
		{
			Mocks.ReplayAll();

			var adapter = GetAdapter();
			var result = adapter.FullName;
		}

		[TestMethod()]
		public void DisplayName_UserHasFirstNameOnly_ReturnsFirstName()
		{
			_user.FirstName = "first name";
			Mocks.ReplayAll();

			var adapter = GetInitializedAdapter();
			var result = adapter.DisplayName;

			result.Should().Be(_user.FirstName);
		}

		[TestMethod()]
		public void DisplayName_UserHasLastNameOnly_ReturnsLastName()
		{
			_user.LastName = "last name";
			Mocks.ReplayAll();

			var adapter = GetInitializedAdapter();
			var result = adapter.DisplayName;

			result.Should().Be(_user.LastName);
		}

		[TestMethod()]
		public void DisplayName_UserHasFullName_ReturnsFullName()
		{
			_user.LastName = "last";
			_user.FirstName = "first";
			Mocks.ReplayAll();

			var adapter = GetInitializedAdapter();
			var result = adapter.DisplayName;

			result.Should().Be(string.Format("{0} {1}", _user.FirstName, _user.LastName));
		}

		[TestMethod()]
		public void DisplayName_UserHasLoginOnly_ReturnsLogin()
		{
			var login = "login";
			SetupResult.For(_user.Login).Return(login);
			Mocks.ReplayAll();

			var adapter = GetInitializedAdapter();
			var result = adapter.DisplayName;

			result.Should().Be(login);
		}
		#endregion

		private UserAdapter GetAdapter()
		{
			return new UserAdapter();
		}

		private UserAdapter GetInitializedAdapter()
		{
			var adapter = GetAdapter();
			adapter.Initialize(_user);
			return adapter;
		}
	}
}
